package com.example.academic_affairs_system.controller;

import com.example.academic_affairs_system.common.R;
import com.example.academic_affairs_system.model.dto.classCourses.TimeTableDTO;
import com.example.academic_affairs_system.model.dto.clazz.HandlerClassDTO;
import com.example.academic_affairs_system.service.IAasClassCoursesService;
import com.example.academic_affairs_system.service.IAasClassService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 前端控制器
 *
 * @author hjx
 * @since 2023-01-31
 */
@RestController
@RequestMapping("/sys/class")
public class AasClassController {
  @Resource IAasClassService iAasClassService;
  @Resource IAasClassCoursesService iAasClassCoursesService;

  @PostMapping("/create")
  public R create(@RequestBody HandlerClassDTO dto) {
    return R.ok(iAasClassService.createClass(dto));
  }

  @PostMapping("/edit")
  public R edit(@RequestBody HandlerClassDTO dto) {
    return R.ok(iAasClassService.edit(dto));
  }

  @GetMapping("/list")
  public R directorList() {
    return R.ok(iAasClassService.getClassByCurrentUser());
  }

  @GetMapping("/info/{id}")
  public R info(@PathVariable("id") Long id) {
    return R.ok(iAasClassService.getClassInfoByClassId(id));
  }

  @GetMapping("/director/class")
  public R directorClass() {
    return R.ok(iAasClassService.getClassStaticsByDirectorsId());
  }

  @PostMapping("/arrange/timetable")
  public R arrangeClassTimetable(@RequestBody TimeTableDTO dto) {
    return R.ok(iAasClassService.arrangeClassTimetable(dto));
  }

  @GetMapping("/courses/{id}")
  public R coursesClass(@PathVariable("id") long id) {
    return R.ok(iAasClassCoursesService.getClassInfoByCoursesId(id));
  }
}
